/**
 * 
 */
package messaage;

import forum.Post;

/**
 * @author Olga
 * 
 */
public class AddedPostMsg extends Message {

	private boolean isViewer;
	private String forumID;
	private String postID;
	private String subject;
	private String author;
	private String date;
	private String parentID;
	private String content;

	public AddedPostMsg(String msg) {
		this.parse(msg);
	}

	public AddedPostMsg(String username, boolean isFriend, String forumID,
			String postID, String subject, String author, String date,
			Post parent, String content) {
		super.username = username;
		this.isViewer = isFriend;
		this.forumID = forumID;
		this.postID = postID;
		this.subject = subject;
		this.author = author;
		this.date = date;
		if (parent == null)
			this.parentID = -1 + "";
		else
			this.parentID = parent.getID() + "";
		this.content = content;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see messaage.Message#toString()
	 */
	@Override
	public String toString() {
		String ans = "AddedPost\n" + 
		this.isViewer + "\n" + 
		this.forumID + "\n" + 
		this.postID + "\n" + 
		this.subject + "\n" + 
		this.author + "\n" + 
		this.date + "\n" + 
		this.parentID + "\n" + 
		this.content + "\0";
		return ans;
	}

	private void parse(String msg) {
		String[] info = msg.split("\n");
		// get isFriend
		this.isViewer = info[1].equals("true");
		// get forumID
		this.forumID = info[2];
		// get PostID
		this.postID = info[3];
		// get subject
		this.subject = info[4];
		// get author
		this.author = info[5];
		// get date
		this.date = info[6];
		this.parentID = info[7];
		this.content = "";
		for (int i = 8; i < info.length; i++) {
			if (i == info.length - 1)
				this.content += info[i];
			else
				this.content += info[i] + "\n";
		}
	}

	/**
	 * @return the isFriend
	 */
	public boolean isFriend() {
		return isViewer;
	}

	/**
	 * @return the forumID
	 */
	public String getForumID() {
		return forumID;
	}

	/**
	 * @return the postID
	 */
	public String getPostID() {
		return postID;
	}

	/**
	 * @return the subject
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * @return the author
	 */
	public String getAuthor() {
		return author;
	}

	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}

	/**
	 * @return the parentID
	 */
	public String getParentID() {
		return parentID;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}

}
